package com.tjx.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tjx.entity.Faq;
import com.tjx.entity.Performance;
import com.tjx.mapper.FaqMapper;
import com.tjx.service.IFaqService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

/**
 * <p>
 * 常见问题表 服务实现类
 * </p>
 *
 * @author tjx
 * @since 2025-10-29
 */
@Service
public class FaqServiceImpl extends ServiceImpl<FaqMapper, Faq> implements IFaqService {

    @Autowired
    private FaqMapper faqMapper;

    /**
     * 查询所有常见问题
     */
    @Override
    public List<Faq> faqQueryAll() {
        QueryWrapper<Faq> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("is_deleted", 0);
        return faqMapper.selectList(queryWrapper);
    }

    /**
     * 新增常见问题
     */
    @Override
    public Integer faqAdd(Faq faq) {
        faq.setCreateDate(LocalDate.now());
        faq.setUpdateDate(LocalDate.now());
        faq.setIsDeleted(0);
        Integer row1 = faqMapper.insert(faq);
        if (row1 > 0) {
            faq.setFaqId("faq" + faq.getId());
            Integer row2 = faqMapper.updateById(faq);
            return row2;
        }
        return row1;
    }

    /**
     * 修改常见问题
     */
    @Override
    public Integer faqUpdate(Faq faq) {
        faq.setUpdateDate(LocalDate.now());
        return faqMapper.updateById(faq);
    }

    /**
     * 删除常见问题
     */
    @Override
    public Integer faqDelete(Faq faq) {
        faq.setIsDeleted(1);
        faq.setUpdateDate(LocalDate.now());
        return faqMapper.updateById(faq);
    }

}
